/*
    XTU OJ: 1240
    by: fifth_light
*/

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(void) {
    while (1) {
        int bottles, lids, gains = 0;
        scanf("%d", &bottles);
        if (bottles == 0) {
            break;        
        }
        // 先把买来的饮料全喝了
        lids = bottles;
        while (bottles >= 2 || lids >= 4) {
            // BREAKPOINT BELOW
            if (lids >= 4) {
                int gain = lids / 4;
                gains += gain;
                lids %= 4;
                bottles += gain;
                lids += gain;
            }
            if (bottles >= 2) {
                int gain = bottles / 2;
                gains += gain;
                bottles %= 2;
                bottles += gain;
                lids += gain;
            }
        }
        printf("%d\n", gains);
    }
    return 0;
}
